<?php
namespace AdminBundle\Repository;


class AuthContentTypeRepository extends BaseRepository
{
    public function loadMenuWithRoot()
    {
        $sql = "SELECT DISTINCT
    app_label AS appLabel, model, note
FROM
    auth_content_type
WHERE
    is_enabled = 1
ORDER BY appLabel , model";
        return $this->rawQuery($sql);
    }

    public function loadMenuWithUser($userid)
    {
        $sql = "SELECT 
    c.app_label AS appLabel, c.model, c.note
FROM
    (SELECT 
        lrp.role_id, lrp.permission_id
    FROM
        auth_user AS u
    INNER JOIN auth_link_user_groups AS lug ON u.id = lug.user_id
    INNER JOIN auth_link_group_roles AS lgr ON lug.group_id = lgr.group_id
    INNER JOIN auth_link_user_roles AS lur ON u.id = lur.user_id
    INNER JOIN auth_link_role_permissions AS lrp ON (lgr.role_id = lrp.role_id
        OR lur.role_id = lrp.role_id)
    WHERE
        u.id = :userid ) AS t
        INNER JOIN
    auth_permission AS p ON t.permission_id = p.id 
        INNER JOIN 
    auth_content_type AS c ON p.content_type_id = c.id
    where c.is_enabled  =1 
        ";
        $params = ['userid' => $userid];
        return $this->rawQuery($sql, $params);
    }
}
